package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    /**
     * 历史订单查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> page(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    OrderVO getOrderDetail(Long id);

    /**
     * 根据id删除订单信息
     * @param id
     */
    @Delete("delete from sky_take_out.orders where id=#{id}")
    void deleteById(Long id);


    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);



    /**
     * 各个状态的订单数量统计
     * @param status
     * @return
     */
    @Select("select count(*) from sky_take_out.orders where status=#{status}")
    Integer getStatusCount(Integer status);

    /**
     * 根据id查询status
     * @param id
     * @return
     */
    @Select("select status from sky_take_out.orders where id=#{id}")
    Integer getStatusById(Long id);

    @Select("select * from sky_take_out.orders where status=#{pendingPayment} and order_time<#{time}")
    List<Orders> getByStatusAndOrdertimeLT(Integer pendingPayment, LocalDateTime time);

    @Select("select * from sky_take_out.orders where id=#{id}")
    Orders getById(Long id);
    /**
     *根据动态条件统计订单数量
     * @param map
     */
    Integer countByMap(Map map);

    /**
     * 查询商品销量排名
     * @param beginTime
     * @param endTime
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);



    Double sumByMap(Map map);
}
